<?php

namespace App\Transformers\User;

use App\Models\Order;
use App\Models\UserInvoice;
use App\Transformers\Order\OrderTransformer;
use App\Transformers\Product\ProductTransformer;
use League\Fractal\TransformerAbstract;

class UserInvoicesTransformer extends TransformerAbstract
{

    protected $availableIncludes = ['user','order'];

    public function transform(UserInvoice $data)
    {
        return [
            'id' => $data->id,
            'user_id'=>$data->user_id ?? '',
            'order_id' => $data->order_id ?? '',
            'header_type'=>$data->header_type ?? 0,
            'type'=>$data->type ?? 0,
            'name'=>$data->name ?? '',
            'duty_number'=>$data->duty_number ?? '',
            'drawer_phone'=>$data->drawer_phone ?? '',
            'email'=>$data->email ?? '',
            'tell'=>$data->tell ?? '',
            'address'=>$data->address ?? '',
            'bank'=>$data->bank ?? '',
            'card_number'=>$data->card_number ?? '',
            'is_default'=>$data->is_default ?? 0,
            'invoice_status' => $data->invoiceStatusEnum[$data->Invoice_status] ?? "",
            'delete_at'=>$data->delete_at ?? '',
            'created_at' => $data->created_at ? $data->created_at->format("Y-m-d H:i:s") : '',
            'updated_at' => $data->updated_at ? $data->updated_at->format("Y-m-d H:i:s") : '',
            'order' => $data->order ?? '',

        ];
    }

    /**
     * 额外包含用户信息
     */
    public function includeUser(UserInvoice $userInvoice)
    {
        return $this->item($userInvoice->user, new UserTransformer());

    }

}
